<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>setTimeout</title>
  <style>
    * {
      font-size: 28px;
    }

    .wrapper {
      margin: 50px;
    }
  </style>
</head>

<body>
  <div class="wrapper">
    <span id="seconds">60</span>
    <div>
      <button id="btnPause">暂停</button>
      <button id="btnContinue">继续</button>
    </div>
  </div>

  <script>
    const secondsEl = document.getElementById("seconds");
    const INTERVAL = 1000;
    let ticket;
    let seconds = 60;
    function setSeconds(val) {
      secondsEl.innerText = val;
    }

    function onTimeout() {
      seconds--;
      setSeconds(seconds);
      ticket = setTimeout(onTimeout, INTERVAL);
    }

    ticket = setTimeout(onTimeout, INTERVAL);

    document.getElementById("btnPause").addEventListener("click", () => {
      clearTimeout(ticket);
    });

    document.getElementById("btnContinue").addEventListener("click", () => {
      ticket = setTimeout(onTimeout, INTERVAL);
    });
  </script>
</body>

</html>